import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
	messTip: null,
	userInfo: {},
	currTag: 1,
	subCurrTag: 1,
	indexModal: {
		isShow: false,
		content: '',
	}, // 进入首页是否需要弹窗
	token: '', // 用户的token
	openID: null,
	orderCurrTag: 1,
	userAvatarInfo: {},
	reportDraft: {
		'name': '',
		'place_of_origin': '',
		'describe':'',
		'price':'',
		'specification':'',
		'units':'',
		'distribution_type':'',
		'supply':'',
		'cycle':'',
		'environment':'',
		'shelf_life':'',
		'delivery_time':'',
		'inside_packing':'',
		'external_packing':'',
		'all_photo':'',
		'inside_photo':'',
		'external_photo':'',
		'remark':'',
	}, // 食材提报草稿
}
const getters = {
	getUserInfo(state) {
		return state.userInfo
	},
	getCurrTag(state) {
		return state.currTag
	},
	getSubCurrTag(state) {
		return state.subCurrTag
	},
	getIndexModal(state) {
		return state.indexModal
	},
	getToken(state) {
		return state.token
	},
	getOpenId(state) {
		return state.openID
	},
	getReportDraft(state) {
		return state.reportDraft
	},
	getOrderCurrTag(state) {
		return state.orderCurrTag
	},
	getUserAvatarInfo(state) {
		return state.userAvatarInfo
	},
	getMessTip(state) {
		return state.messTip
	}
}
const mutations = {
	setMessTip(state, payload) {
		state.messTip = payload
	},
	setUserInfo(state, payload) {
		state.userInfo = payload
	},
	setCurrTag(state, payload) {
		state.currTag = payload
	},
	setSubCurrTag(state, payload) {
		state.subCurrTag = payload
	},
	setIndexModal(state, payload) {
		if (parseInt(payload.if_show) === 0) {
			state.indexModal.isShow = true
		} else {
			state.indexModal.isShow = false
		}
		if (payload.content) {
			state.indexModal.content = payload.content
		}
	},
	setToken(state, payload) {
		state.token = payload
	},
	setOpenId(state, payload) {
		state.openID = payload
	},
	setReportDraftType2(state, payload){
		state.reportDraft = JSON.parse(JSON.stringify(payload))
	},
	setReportDraft(state, payload) {
		payload = JSON.parse(JSON.stringify(payload))
		if (payload.name || payload.name === '') {
			Vue.set(state.reportDraft, 'name', payload.name)
		}
		 if (payload.address || payload.address === '') {
			Vue.set(state.reportDraft, 'place_of_origin', payload.address)
		}
		 if (payload.quality || payload.quality === '') {
			Vue.set(state.reportDraft, 'describe', payload.quality)
		}
		 if (payload.price || payload.price === '') {
			Vue.set(state.reportDraft, 'price', payload.price)
		}
		 if (payload.unit || payload.unit === '') {
			Vue.set(state.reportDraft, 'units', payload.unit)
		}
		 if (payload.norm || payload.norm === '') {
			Vue.set(state.reportDraft, 'specification', payload.norm)
		}
		 if (payload.innerPackaging || payload.innerPackaging === '') {
			Vue.set(state.reportDraft, 'inside_packing', payload.innerPackaging)
		}
		 if (payload.outerPackaging || payload.outerPackaging === '') {
			Vue.set(state.reportDraft, 'external_packing', payload.outerPackaging)
		}
		 if (payload.type || payload.type === '') {
			Vue.set(state.reportDraft, 'distribution_type', payload.type)
		}
		 if (payload.supply || payload.supply === '') {
			Vue.set(state.reportDraft, 'supply', payload.supply)
		}
		 if (payload.aging || payload.name === '') {
			Vue.set(state.reportDraft, 'delivery_time', payload.aging)
		}
		 if (payload.cycle || payload.cycle === '') {
			Vue.set(state.reportDraft, 'cycle', payload.cycle)
		}
		 if (payload.remarks || payload.remarks === '') {
			Vue.set(state.reportDraft, 'remark', payload.remarks)
		} 
		if (payload.saveType || payload.saveType === '') {
			Vue.set(state.reportDraft, 'environment', payload.saveType)
		} 
		if (payload.shelfLife || payload.shelfLife === '') {
			Vue.set(state.reportDraft, 'shelf_life', payload.shelfLife)
		}
		if (payload.imgPath) {
			if (payload.imgPath.wholeBody || payload.imgPath.wholeBody === '') {
				Vue.set(state.reportDraft, 'all_photo', payload.imgPath.wholeBody)
			}
			if (payload.imgPath.innerPackaging || payload.imgPath.innerPackaging === '') {
				Vue.set(state.reportDraft, 'inside_photo', payload.imgPath.innerPackaging)
			}
			if (payload.imgPath.outerPackaging || payload.imgPath.outerPackaging === '') {
				Vue.set(state.reportDraft, 'external_photo', payload.imgPath.outerPackaging)
			}

		}
	},
	setReportDraftBeNone(state){
		for(let index in state.reportDraft) {
			state.reportDraft[index] = ''
		}
	},
	setOrderCurrTag(state, payload) {
		state.orderCurrTag = payload
	},
	setUserAvatarInfo(state, payload) {
		state.userAvatarInfo = payload
	}
}
const actions = {

}

const store = new Vuex.Store({
	state,
	getters,
	mutations,
	actions,
})

export default store
